package com.newtouch.bxzs.policy.util;

import com.newtouch.bxzs.common.base.BaseException;
import com.newtouch.bxzs.common.base.util.CheckCertificateTypeUtil;
import com.newtouch.bxzs.common.base.util.DateLengthCheckUtils;
import com.newtouch.bxzs.common.base.util.NumberLengthCheckUtils;
import org.springframework.util.StringUtils;

import java.util.Date;

/**
 * 查询条件校验工具类
 *
 * <p>
 * <b>History:</b>
 * <table border="1">
 * <tr>
 * <th>Date</th>
 * <th>Operator</th>
 * <th>Memo</th>
 * </tr>
 * <tr>
 * <td>2021/2/3 13:39</td>
 * <td>linhongxi</td>
 * <td>Create</td>
 * </tr>
 * </table>
 *
 * @author linhongxi
 * @version 1.0.0
 * @since 1.0.0
 */
public class QueryCriteriaUtils {

    public static void queryValidationByDate(Date startDate,Date endDate){
        DateLengthCheckUtils.dateLengthCheck(startDate,endDate);

    }

    public static void queryValidationByNumber(String policyNumber){

        // 查询条件-保单号如果不为空则进行格式验证
        if(!StringUtils.isEmpty(policyNumber)){
            NumberLengthCheckUtils.formatValidation(policyNumber);
            NumberLengthCheckUtils.lengthCheck(policyNumber);
        }

    }

    public static void queryValidationByName(String holderName,String insurederName){
        // 查询条件-投保人姓名验证
        if(!StringUtils.isEmpty(holderName)) {
            NumberLengthCheckUtils.lengthCheck(holderName);
        }
        // 查询条件-被保人姓名验证
        if(!StringUtils.isEmpty(insurederName)) {
            NumberLengthCheckUtils.lengthCheck(insurederName);
        }
    }
    public static void queryValidationByCompanyName(String companyName){
        // 查询条件-投保公司名称验证
        if(!StringUtils.isEmpty(companyName)) {
            NumberLengthCheckUtils.companyNameCheck(companyName);
        }
    }

    public static void queryValidationByCertificate(String certificateType, String certificateNumber){
        //查询条件-证件号码和证件类型验证
        if( StringUtils.isEmpty(certificateNumber) && !StringUtils.isEmpty(certificateType)) {
            throw new BaseException("-1","证件号码和证件类型需要同时录入");
        }
        if( !StringUtils.isEmpty(certificateNumber) && StringUtils.isEmpty(certificateType)) {
            throw new BaseException("-1","证件号码和证件类型需要同时录入");
        }
        if(!StringUtils.isEmpty(certificateType) && !StringUtils.isEmpty(certificateNumber) ) {
            CheckCertificateTypeUtil.checkCertificate(certificateType,certificateNumber);
        }
    }

}
